var elUsername=document.getElementById('username');
var elPassword=document.getElementById('password');
elMsg=document.getElementById('feedback');
elMsg_2=document.getElementById('feed');

console.log(elUsername);

var xhr='';

function checkUsername(username){
    if(username==null||username==''||username.length==0){
        elMsg.textContent="用户名不能为空";
        return;
    }
    if(username.length<=3){
        elMsg.textContent="用户名长度必须大于3";
        return;
    }
    elMsg.textContent='';
}

function checkPassWord(password){
    if(password==null||password==''||password.length==0){
        elMsg_2.textContent="密码不能为空";
        return;
    }
    if(password.length<=3){
        elMsg_2.textContent="密码长度必须大于3";
        return;
    }
    elMsg_2.textContent='';
}

function sendRequest(username){
    xhr=new XMLHttpRequest();
    xhr.onreadystatechange=process;
    xhr.open('GET','usernameIsExist?username='+username);
    xhr.send(null);
}

function process(){//回调
    if(xhr.readyState==4){
        if(xhr.status==200){
            var responseInfo=xhr.responseText;
            console.log((responseInfo));
            if(responseInfo=='Exist'){
                elMsg.textContent='用户名已存在';
            }else{
                elMsg.textContent='';
            }
        }
    }
}


$('#username').on('blur',function (){
    var username=elUsername.value.trim();
    checkUsername(username);
})
$('#password').on('blur',function (){
    var password=elPassword.value.trim();
    checkPassWord(password,username);
})
